package com.pay.game.central.utils;

import com.auth0.jwt.JWT;
import com.pay.game.central.utils.bean.MyHeader;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class RequestUtils {

    public static MyHeader parseHeader(Map<String,String> headers){
        String token = headers.get("x-token");
        String userId = JWT.decode(token).getAudience().get(0);
        List<String> roles = new ArrayList<>();
        String[] rs = headers.get("x-roles").split("-");
        for (String item: rs) {
            roles.add(item);
        }
        MyHeader myHeader = new MyHeader();
        myHeader.setRoles(roles);
        myHeader.setUserId(userId);
        return myHeader;
    }
}
